var app = new Vue({
	el: '#app',
	data: {
		infos:{
			user:globalData.userInfo
		},//用户的所有信息
		url:{
			getQAUsers: '/api/UserQuestion/GetQAUsers', //获取用户列表
			getProductCategorysForApp: '/api/ProductCategory/GetProductCategorysForApp', //获取类别
			getRecommendProductsByModelID: '/api/Product/GetRecommendProductsByModelID', //获取推荐产品
			getRequirementAnalysisImgs:'/api/Banner/GetRequirementAnalysisImgs', //引导图
		},
		type:0, //产品库，需求分析
		modelList:[],  //分类
		recommend_products:[], //推荐产品列表
		list_item:{}, //详情列表父item
		product_list_detail_show:{value:false}, //详情列表
		users:[], //用户列表
		user:globalData.getUserInfo(),
		CustomerID:'', //客户ID
		guide_map:[], //引导图
		children_data: {
			component_data: {
				nextQuestionID: "", //下题ID 
				selectedValue: "", //当前问题的值 
				isStop: false,
				hasTip: false,
				ShowMsg: ''
			},
			control9_10_data: {
				parent_value: [],
				control_out: {
					err: "",
					result: "",
					all_values: ""
				}
			},
			current_question: {},
			currentIndex: 0, //组件中当前题是第几题
			isShow: true, //tab内容、答题内容 切换
			question_step: 0, //答题步骤，基本、问答、推荐
			CustomerID: '', //客户ID
			AnswerItems: [], //答案列表
			answers: {
				name: '',
				mark: '',
				sex: '',
				birthday: '',
				birthplace: '',
				county: '',
				address: '',
				marriage: '',
				hasChild: '',
				occupation: '',
				workyear: '',
				isPep: '',
				industry: '',
				income: '',
				male: '',
				female: ''
			},
			evaluation_result:{}, //评估结果
		},
	},
	watch:{
		'children_data.evaluation_result':function(val,oldval){
			this.reset_charts()
		}
	},
	computed:{
		childs:function(){
			return (this.answers.male + ',' + this.answers.male)
		}		
	},
	mounted: function() {
		var that = this
		globalData.getTempToken(function(){				
			//获取 产品类别
			that.getProductCategorysForApp()
			//获取推荐产品
			that.getRecommendProductsByModelID()
			
		})		
	},
	methods: {
		showProductLibrary:function(){
			this.type = 0
			globalData.utils.scrool_top()
		},
		showUsers:function(){ //切换tab到用户列表
			var that = this
			if(!globalData.userIsLogin(null,true)){
				return;
			}
			that.type = 1
			globalData.utils.scrool_top()
			this.getQAUsers() //获取用户	
			
		},
		getProductCategorysForApp: function() {
			var that = this
			globalData.ajaxPost(that.url.getProductCategorysForApp,{'ModelID':globalData.getStorage('modelID')},function(res){
				//隐藏loading
				$('.loading').hide()	
				if(res.suc){
					console.log(res)
					that.modelList = res.data.ProductCategorys
				}
			})
		},
		getRecommendProductsByModelID: function() {
			var that = this
			globalData.ajaxPost(that.url.getRecommendProductsByModelID,{'ModelID':globalData.getStorage('modelID')},function(res){
				if(res.suc){
					console.log(res)
					that.recommend_products = res.data
				}
			})
		},
		go_step_2: function(val) { //保存基本问题
			var that = this;
			var data = { 
				"ModelName": "高端生活",
				"UserAnswers": [{ "LoopTag": 1, "AnswerItems": val}]
				}
			console.log(data)
			globalData.ajaxPost(this.url.saveBasicQuestions, data, function(res) {
				if(res.StatusCode == 200) {
					//保存成功，返回客户id
					that.CustomerID = res.data
					console.log(res)
					that.step = 2
				}
			})
		},
		add_customer: function() {
			var that = this
			that.children_data.CustomerID = ''
			//初始化
			$.each(that.children_data.answers, function(name, value) {
				that.children_data.answers[name] = ''
			})
			console.log(that.children_data.answers)
			that.children_data.isShow = false
			that.children_data.question_step = 1
		},
		modify_userinfo:function(item){
			var that = this
			console.log(item)
			//赋值customer id
			that.children_data.CustomerID = item.ID
			that.children_data.isShow = false
			that.children_data.question_step = 1
		},
		//获取步骤二数据
		get_my_question:function(){
			var that = this
			var data = {
				"ModelID":"3",
				"QuestionType":2
			}
			globalData.ajaxPost(this.url.getSpecialQuestions, data, function(res) {				
				var data = res.data
				if(res.suc){
					console.log(data)
					that.AnswerOutputs = data[0].AnswerOutputs
					that.QuestionTitle = data[0].QuestionTitle
					console.log(that.AnswerOutputs)
				}
			})
		},
		getQAUsers: function() {
			var that = this
			globalData.ajaxPost(this.url.getQAUsers, null, function(res) {
				console.log(res)
				if(res.suc) {
					if(res.data.length==0){
						that.getRequirementAnalysisImgs()
					}
					console.log(res.data)
					that.users = res.data
				}
			})
		},
		getRequirementAnalysisImgs:function(){ //引导图
			var that = this
			globalData.ajaxPost(this.url.getRequirementAnalysisImgs, null, function(res) {
				console.log(res)
				if(res.suc) {					
					console.log(res.data)
					that.guide_map = res.data
					$("#modal_photos").modal()
					setTimeout(function(){
						self.mySwiper = new Swiper('.swiper-container', {
							loop: true,
							// 如果需要分页器
							pagination: '.swiper-pagination',
							freeMode:false,
							initialSlide:0,
							speed:10,
							autoplay:3000,
							autoplayDisableOnInteraction : false,
							// 如果需要前进后退按钮
							nextButton: '.swiper-button-next',
							prevButton: '.swiper-button-prev'
						})
					},100)
				}
			})
		},
		show_list:function(item){  //获取类别详情页
			console.log(item)
			var that = this 
			that.list_item = item
			
			
			$('.product_list_detail').show()
			this.product_list_detail_show.value = true
		},
		go_introduce:function(item){
			//判断是否登录，登录跳转到详情页，未登录弹出简介
			console.log(item)
			if(!globalData.userInfo.isLogin) {
				this.$refs.m_modal.more_info_show(item.ProductName, item.ProductNote)
				return;
			}
			go_product_introduct(item)
		},
		go_customers_list:function(){ //答题完毕，返回用户列表
			var that = this
			that.children_data.isShow = true
			that.children_data.question_step = 0
			that.getQAUsers() //获取用户
		},
		reset_charts:function(){
			 // 基于准备好的dom，初始化echarts实例
	        var myChart = echarts.init(document.getElementById('main'));
			var mychart_data = this.children_data.evaluation_result.FI[0].InvCategoryLevel
			
			var test = []
			$.each(mychart_data.InvCategorys,function(index,item){
				test.push({
					value:item.InvCategoryPercent,
					name:item.InventuryCategoryName
				})
			})
	        option = {
			    backgroundColor: '#2c343c',			
			    title: {
			        text: mychart_data.InvCategoryLevel,
			        left: 'center',
			        top: 20,
			        textStyle: {
			            color: '#ccc'
			        }
			    },			
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {d}%"
			    },
			
			    visualMap: {
			        show: false,
			        min: 400,
			        max: 600,
			        inRange: {
			            colorLightness: [0, 1]
			        }
			    },
			    series : [
			        {
			            name:'访问来源',
			            type:'pie',
			            radius : '55%',
			            center: ['50%', '50%'],
			            data:test,
//			            .sort(function (a, b) { return a.value - b.value; }),
			            roseType: 'radius',
			            label: {
			                normal: {
			                    textStyle: {
			                        color: 'rgba(255, 255, 255, 0.3)'
			                    }
			                }
			            },
			            labelLine: {
			                normal: {
			                    lineStyle: {
			                        color: 'rgba(255, 255, 255, 0.3)'
			                    },
			                    smooth: 0.2,
			                    length: 10,
			                    length2: 20
			                }
			            },
			            itemStyle: {
			                normal: {
			                    color: '#c23531',
			                    shadowBlur: 200,
			                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			                }
			            },
			
			            animationType: 'scale',
			            animationEasing: 'elasticOut',
			            animationDelay: function (idx) {
			                return Math.random() * 200;
			            }
			        }
			    ]
			};
	
	        // 使用刚指定的配置项和数据显示图表。
	        myChart.setOption(option);
		}
	},
	filters: {
		
	}
})



